package com.ruoyi.personnel.salary.calculation.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.calculation.domain.CalculationCond;
import com.ruoyi.personnel.salary.calculation.domain.CalculationDomain;
import com.ruoyi.personnel.salary.calculation.service.ICalculationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工资计算控制层
 * @author lsy 2021.7.20
 */
@RestController
@RequestMapping("/salary/calculation")
@Api(value = "工资计算信息模块", tags = "工资计算接口")
public class CalculationController extends BaseController {

    @Autowired
    private ICalculationService calculationService;

    /**
     * 获取工资计算记录列表
     * @return
     */
    @ApiOperationSupport(includeParameters = {"CalculationCond.calculationItemName"})
    @ApiOperation(value = "获取工资计算列表",notes = "查询所有工资计算信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CalculationCond cond) {
        startPage();
        List<CalculationDomain> calculationDtoList = calculationService.selectCalculationList(cond);
        return getDataTable(calculationDtoList);
    }

    /**
     * 新增工资计算记录
     *
     * @param calculation
     * @return
     */
    @ApiOperation(value = "新增工资计算记录", notes = "新增工资计算记录信息")
    @ApiImplicitParam(name = "calculation", value = "新增工资计算记录", dataType = "CalculationDomain")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CalculationDomain calculation) {
        return toAjax(calculationService.insertCalculation(calculation));
    }

    /**
     * 修改工资计算记录
     *
     * @param calculation
     * @return
     */
    @ApiOperation(value = "修改工资计算记录", notes = "修改工资计算记录信息")
    @ApiImplicitParam(name = "calculation", value = "修改工资计算记录(可修改参数：calculationItemName、calculationItemType、calculationInitialValue、calculationItemOrder、calculationItemFormula、calculationItemVisible、remark)", dataType = "CalculationDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody CalculationDomain calculation) {
        return toAjax(calculationService.updateCalculation(calculation));
    }

    /**
     * 删除工资计算记录
     * 仅修改删除标志位
     *
     * @param calculation
     * @return
     */
    @ApiOperation(value = "删除工资计算记录", notes = "删除工资计算记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody CalculationDomain calculation) {
        return toAjax(calculationService.updateCalculationDeleteFlag(calculation));
    }

    /**
     * 获取所有数据字段
     * @return
     */
    @ApiOperation(value = "获取所有数据字段", notes = "获取所有数据字段")
    @GetMapping("/dataFiled")
    public AjaxResult getALLDataField() {
        List<String> allDataField = calculationService.getALLDataField();
        return AjaxResult.success("查询成功", allDataField);
    }
}
